package com.ybkj.daijia.api.driver.v4;

import com.ybkj.daijia.ServiceSetting;
import com.ybkj.daijia.Setting;
import com.ybkj.daijia.api.driver.DeviceInfoData;
import com.ybkj.daijia.api.driver.transport.ResultTransport;
import com.ybkj.daijia.api.util.ErrorConstantV4;
import com.ybkj.daijia.server.event.model.DriverOfflineEvent;
import com.ybkj.daijia.server.event.model.DriverOnlineEvent;
import com.ybkj.daijia.server.freight.Truck;
import com.ybkj.daijia.server.model.Company;
import com.ybkj.daijia.server.model.Driver;
import com.ybkj.daijia.server.model.DriverLogin;
import com.ybkj.daijia.server.model.DriverRebate;
import com.ybkj.daijia.server.service.CompanyService;
import com.ybkj.daijia.server.service.DriverApplyService;
import com.ybkj.daijia.server.service.DriverLoginService;
import com.ybkj.daijia.server.service.DriverPaymentsRecordService;
import com.ybkj.daijia.server.service.DriverRebateService;
import com.ybkj.daijia.server.service.DriverService;
import com.ybkj.daijia.server.service.DriverTimeService;
import com.ybkj.daijia.server.service.ErrandService;
import com.ybkj.daijia.server.service.FreightService;
import com.ybkj.daijia.server.service.OrderService;
import com.ybkj.daijia.server.service.ZhuancheService;
import com.ybkj.daijia.server.service.ZhuanxianService;
import com.ybkj.daijia.server.service.impl.DefaultDriverRebateService;
import com.ybkj.daijia.server.websocket.WebSocketSend;
import com.ybkj.daijia.server.zhuan.Car;
import com.ybkj.daijia.server.zhuan.CarType;
import com.ybkj.daijia.server.zhuanxian.Line;
import com.ybkj.daijia.serverUtils.ServiceUtil;
import com.ybkj.daijia.serverUtils.SettingUtils;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.util.WebUtils;

/**
 * 司机登录相关
 * @author bo
 *
 */
@Controller("DriverAccountUpControllerV4")
@RequestMapping(value = "driver/api/rest/v4/up")
@Slf4j
public class DriverAccountUpController {

    @Autowired
    private DriverService driverService;
    @Autowired
    private DriverTimeService driverTimeService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private ZhuancheService zhuancheService;
    @Autowired
    private ErrandService errandService;
    @Autowired
    private FreightService freightService;
    @Autowired
    private ZhuanxianService zhuanxianService;
    @Autowired
    private DriverLoginService driverLoginService;
    @Autowired
    private DriverApplyService driverApplyService;
    @Autowired
    private DriverPaymentsRecordService driverPaymentsRecordService;
    @Autowired
    private DriverRebateService driverRebateService;
    @Autowired
    private SettingUtils settingUtils;
    @Autowired
    private ApplicationEventMulticaster applicationEventMulticaster;
    @Autowired
    private DefaultDriverRebateService defaultDriverRebateService;

    /**
     * 修改司机密码
     *
     * @param oldPass
     * @param newPass
     * @return
     */
    @RequestMapping(value = "modifyPass", method = RequestMethod.POST)
    public @ResponseBody
    ResultTransport modifyPass(String employToken, String oldPass, String newPass) {

        log.debug("recv employToken:{},oldPass:{},newPass:{}", employToken, oldPass, newPass);

        if (StringUtils.isBlank(employToken) || StringUtils.isBlank(oldPass) || StringUtils
            .isBlank(newPass)) {
            return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
        }

        DriverLogin driverLogin = driverLoginService.selectByToken(employToken);

        if (null == driverLogin) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_ERROR);
        }

        if (System.currentTimeMillis() >= driverLogin.getDeathDate().getTime()) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_TIME_ERROR);
        }

        Driver driver = driverService.findOne(driverLogin.getDriverId());

        if (null == driver) {
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_NOT_EXISTS);
        }

        try {

            Sha256Hash sha256Hash = new Sha256Hash(oldPass);

            if (!sha256Hash.toBase64().equals(driver.getPassword())) {
                return ResultTransport.getErrorBy(ErrorConstantV4.PASS_NOT_CORRECT_ERROR);
            }

            if (newPass.length() < 4 || newPass.length() > 20 || !newPass
                .matches("^[^\\s&\"<>]+$")) {
                return ResultTransport.getErrorBy(ErrorConstantV4.PASS_FORMAT_ERROR);
            }

            sha256Hash = new Sha256Hash(newPass);
            driver.setPassword(sha256Hash.toBase64());
            driverService.updateByPassword(sha256Hash.toBase64(), driver.getId());

            Calendar calendar = Calendar.getInstance();
            driverLogin.setDeathDate(calendar.getTime());
            driverLoginService.update(driverLogin);

            return ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS); //密码修改成功

        } catch (Exception e) {
            log.error("api v4 driver modifyPass error: {}", e);
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }


    }

    /**
     * 设置司机目前为上班状态
     *
     * @return
     */
    @RequestMapping(value = "online", method = RequestMethod.POST)
    public @ResponseBody
    ResultTransport online(String employToken) {


        if (StringUtils.isBlank(employToken)) {
            return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
        }

        DriverLogin driverLogin = driverLoginService.selectByToken(employToken);

        if (null == driverLogin) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_ERROR);
        }

        if (System.currentTimeMillis() >= driverLogin.getDeathDate().getTime()) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_TIME_ERROR);
        }

        Driver driver = driverService.findOne(driverLogin.getDriverId());

        if (null == driver) {
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_NOT_EXISTS);
        }

        if (driver.getIsFreeze()) { //帐号被冻结
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_IS_FREEZE_ERROR);
        }

        Setting setting = settingUtils.get();
        if (driver.getType().equals(Driver.DRIVER_TYPR_PARTTIME)
            && setting.getLowestWorkVirtual() != 0
            && driver.getVirtual().doubleValue() < setting.getLowestWorkVirtual()) {

            return ResultTransport.getErrorBy(ErrorConstantV4.LOWEST_WORK_VIRTUAL_ERROR);

        }

        try {

            if (driver.getStatus().equals(Driver.DRIVER_OFFLINE)) {
                driver.setStatus(Driver.DRIVER_ONLINE);
                driver.setDutyTime(new Date());
                driverService.online(driver);

                DriverOnlineEvent driverOnlineEvent = new DriverOnlineEvent(driver);
                applicationEventMulticaster.multicastEvent(driverOnlineEvent);
            }

            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS); //上班成功
            instance.setData(driver.getStatus());

            return instance;

        } catch (Exception e) {
            log.error("api v4 driver online error: {}", e);
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }

    /**
     * 司机请求设置上班状态
     *
     * @returns
     */
    @RequestMapping(value = "onlined", method = RequestMethod.POST)
    public @ResponseBody
    ResultTransport onlined(String employToken) {

        log.debug("recv employToken:{}", employToken);

        if (StringUtils.isBlank(employToken)) {
            return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
        }

        DriverLogin driverLogin = driverLoginService.selectByToken(employToken);

        if (null == driverLogin) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_ERROR);
        }

        if (System.currentTimeMillis() >= driverLogin.getDeathDate().getTime()) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_TIME_ERROR);
        }

        Driver driver = driverService.findOne(driverLogin.getDriverId());

        if (null == driver) {
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_NOT_EXISTS);
        }

        if (driver.getIsFreeze()) { //帐号被冻结
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_IS_FREEZE_ERROR);
        }

        Setting setting = settingUtils.get();
        if (driver.getType().equals(Driver.DRIVER_TYPR_PARTTIME)
            && setting.getLowestWorkVirtual() != 0
            && driver.getVirtual().doubleValue() < setting.getLowestWorkVirtual()) {

            return ResultTransport.getErrorBy(ErrorConstantV4.LOWEST_WORK_VIRTUAL_ERROR);
        }

        try {

            if (driver.getStatus() == Driver.DRIVER_OFFLINE) {
                driver.setStatus(Driver.DRIVER_ONLINE);
                driver.setDutyTime(new Date());

                driverService.online(driver);

                DriverOnlineEvent driverOnlineEvent = new DriverOnlineEvent(driver);
                applicationEventMulticaster.multicastEvent(driverOnlineEvent);
            }

            driver.setCompany(companyService.findOne(driver.getCompanyId()));

            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS); //上班成功
            instance.setData(driver);

            return instance;

        } catch (Exception e) {
            log.error("api v4 driver onlined error: {}", e);
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }

    /**
     * 设置司机目前为下线状态
     *
     * @return
     */
    @RequestMapping(value = "offline", method = RequestMethod.POST)
    public @ResponseBody
    ResultTransport offline(String employToken) {

        log.debug("recv employToken:{}", employToken);

        if (StringUtils.isBlank(employToken)) {
            return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
        }

        DriverLogin driverLogin = driverLoginService.selectByToken(employToken);

        if (null == driverLogin) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_ERROR);
        }

        if (System.currentTimeMillis() >= driverLogin.getDeathDate().getTime()) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_TIME_ERROR);
        }

        Driver driver = driverService.findOne(driverLogin.getDriverId());

        if (null == driver) {
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_NOT_EXISTS);
        }

        try {

            try {
                ServiceSetting serviceSetting = ServiceUtil.checkOpen();

                if (serviceSetting.isDaijia()) {
                    Long daijiaAmount = orderService.countActivedOrdersByDriver(driver.getId());
                    if (daijiaAmount > 0) {
                        return ResultTransport
                            .getErrorBy(ErrorConstantV4.HAS_ACTIVED_DAIJIA_ORDER_ERROR);
                    }
                }

                if (serviceSetting.isZhuanche()) {
                    Long zhuancheAmount = zhuancheService
                        .countActivedOrdersByDriver(driver.getId());
                    if (zhuancheAmount > 0) {
                        return ResultTransport
                            .getErrorBy(ErrorConstantV4.HAS_ACTIVED_ZHUANCHE_ORDER_ERROR);
                    }
                }

                if (serviceSetting.isPaotui()) {
                    Long paotuiAmount = errandService.countBusyAmount(driver.getId());
                    if (paotuiAmount > 0) {
                        return ResultTransport
                            .getErrorBy(ErrorConstantV4.HAS_ACTIVED_PAOTUI_ORDER_ERROR);
                    }
                }

                if (serviceSetting.isFreight()) {
                    Long freightAmount = freightService.countActivedOrdersByDriver(driver.getId());
                    if (freightAmount > 0) {
                        return ResultTransport
                            .getErrorBy(ErrorConstantV4.HAS_ACTIVED_FREIGHT_ORDER_ERROR);
                    }
                }

                if (serviceSetting.isZhuanxian()) {
                    Long zhuanxianAmount = zhuanxianService
                        .countActivedOrdersByDriver(driver.getId());
                    if (zhuanxianAmount > 0) {
                        return ResultTransport
                            .getErrorBy(ErrorConstantV4.HAS_ACTIVED_ZHUANXIAN_ORDER_ERROR);
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }

            driver.setStatus(Driver.DRIVER_OFFLINE);
            driverService.updateStatusAndJobStatus(Driver.DRIVER_OFFLINE, null, driver.getId());

            DriverOfflineEvent offlineEvent = new DriverOfflineEvent(driver);
            applicationEventMulticaster.multicastEvent(offlineEvent);

            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS); //上班成功
            instance.setData(Driver.DRIVER_OFFLINE);

            return instance;

        } catch (Exception e) {
            log.error("api v4 driver offline error: {}", e);
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }

    /**
     * 获取服务人员
     *
     * @return
     */
    @RequestMapping(value = "getEmploy", method = RequestMethod.GET)
    public @ResponseBody
    ResultTransport getDriver(String employToken) {

        log.debug("recv employToken:{}", employToken);

        if (StringUtils.isBlank(employToken)) {
            return ResultTransport.getErrorBy(ErrorConstantV4.PARAM_ERROR);
        }

        DriverLogin driverLogin = driverLoginService.selectByToken(employToken);

        if (null == driverLogin) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_ERROR);
        }

        if (System.currentTimeMillis() >= driverLogin.getDeathDate().getTime()) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_TIME_ERROR);
        }

        Driver driver = driverService.findOne(driverLogin.getDriverId());

        if (null == driver) {
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_NOT_EXISTS);
        }

        try {
            Setting setting = settingUtils.get();
            Company company = companyService.findOne(driver.getCompanyId());

            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", driver.getId());
            map.put("name", driver.getName());
            map.put("realName", driver.getRealname());
            map.put("userName", driver.getUsername());
            map.put("phone", driver.getPhone());
            map.put("companyAbbreviation", company.getAbbreviation());
            map.put("companyTelephone", company.getTelephone());
            map.put("virtual", driver.getVirtual());
            map.put("starLevel", driver.getStarLevel());
            map.put("status", driver.getStatus());
            map.put("longitude", driver.getLongitude());
            map.put("latitude", driver.getLatitude());
            map.put("driverJobType", driver.getDriverJobType());
            map.put("workCar", driver.isWorkCar());
            map.put("companyId", driver.getCompanyId());
            map.put("bankName", driver.getBankName());
            map.put("bankNo", driver.getBankNo());
            map.put("skrName", driver.getSkrName());
            map.put("remarks", setting.getRemarks());
            if (StringUtils.isNotBlank(driver.getPhoto())) {
                map.put("photo", setting.getWebUrl() + "/upload/driver/" + driver.getPhoto());
            } else {
                map.put("photo", null);
            }
            String shareUrl = defaultDriverRebateService.getWeixinShareCodeUrl(driver);
            map.put("shareUrl", shareUrl);

            //查询本月收入
            Calendar calendaer = Calendar.getInstance();
            calendaer.set(Calendar.DAY_OF_MONTH, 1);
            calendaer.set(Calendar.HOUR_OF_DAY, 0);
            calendaer.set(Calendar.MINUTE, 0);
            calendaer.set(Calendar.SECOND, 0);
            Date begin = calendaer.getTime();
            BigDecimal thisMonthInCome = driverPaymentsRecordService
                .sumInComeByEmployWithDate(driver.getId(), begin, null);
            map.put("thisMonthInCome", thisMonthInCome);

            //车辆类型
            if (StringUtils.isNotBlank(driver.getDriverJobType()) && driver.getDriverJobType()
                .contains(Driver.DriverJobType.zhuanche.toString())) {
                if (null != driver.getCarId()) {
                    Car car = zhuancheService.findCar(driver.getCarId());
                    if (null != car) {
                        map.put("carName_zhuan", car.getCarName());
                        map.put("carNumber_zhuan", car.getCarNumber());
                        if (null != car.getCarTypeId()) {
                            CarType carType = zhuancheService.findCarType(car.getCarTypeId());
                            if (null != carType) {
                                map.put("carTypeName_zhuan", carType.getTypeName());
                                map.put("carTypeId_zhuan", carType.getId());
                            }
                        }
                    }
                }
            }
            if (StringUtils.isNotBlank(driver.getDriverJobType()) && driver.getDriverJobType()
                .contains(Driver.DriverJobType.freight.toString())) {
                if (null != driver.getTruckId()) {
                    Truck truck = freightService.findTruck(driver.getTruckId());
                    if (null != truck) {
                        map.put("carName_freight", truck.getName());
                        map.put("carNumber_freight", truck.getCarNumber());
                        map.put("carTypeName_freight", truck.getTruckTypeName());
                    }
                }
            }
            if (StringUtils.isNotBlank(driver.getDriverJobType()) && driver.getDriverJobType()
                .contains(Driver.DriverJobType.zhuanxian.toString())) {
                if (null != driver.getZhuanxianCarId()) {
                    com.ybkj.daijia.server.zhuanxian.Car car = zhuanxianService
                        .findCar(driver.getZhuanxianCarId());
                    if (null != car) {
                        map.put("carSeats_zhuanxian", car.getRidepeopleNumber());
                        map.put("carName_zhuanxian", car.getCarName());
                        map.put("carNumber_zhuanxian", car.getCarNumber());
                        List<Line> lines = car.getLines();
                        if (!CollectionUtils.isEmpty(lines)) {
                            map.put("carLineName_zhuanxian", lines.get(0).getName());
                        } else {
                            map.put("carLineName_zhuanxian", "");
                        }
                    }
                }
            }

            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
            instance.setData(map);

            return instance;

        } catch (Exception e) {
            log.error("api v4 driver getEmploy error: {}", e);
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }

    /**
     * 获取设备信息
     *
     * @return
     */
    @RequestMapping(value = "getDeviceInfo", method = RequestMethod.GET)
    public @ResponseBody
    ResultTransport getDeviceInfo(DeviceInfoData data) {

        DriverLogin driverLogin = driverLoginService.selectByToken(data.getEmployToken());

        if (null == driverLogin) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_ERROR);
        }

        if (System.currentTimeMillis() >= driverLogin.getDeathDate().getTime()) {
            return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_TIME_ERROR);
        }

        Driver driver = driverService.findOne(driverLogin.getDriverId());

        if (null == driver) {
            return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_NOT_EXISTS);
        }

        try {

            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);

            //推送
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("type", "deviceinfo");
            jsonObject.put("driverId", driver.getId());
            jsonObject.put("networkType", data.getNetworkType());
            jsonObject.put("mobileVersion", data.getMobileVersion());
            jsonObject.put("operatorName", data.getOperatorName());
            jsonObject.put("systemVersion", data.getSystemVersion());
            jsonObject.put("ip", data.getIp());
            jsonObject.put("gps", data.isGps());
            jsonObject.put("root", data.isRoot());
            jsonObject.put("runningBackground", data.isRunningBackground());
            jsonObject.put("wifi", data.isWifi());
            Company mainCompany = companyService.getMain();
            Company driverCompany = companyService.findOne(driver.getCompanyId());
            WebSocketSend
                .boardcastToCompany(jsonObject, driverCompany.getId(), mainCompany.getId());

            return instance;

        } catch (Exception e) {
            log.error("api v4 driver getDeviceInfo error: {}", e);
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }

    /**
     * 获取配置
     *
     * @return
     */
    @RequestMapping(value = "getSettings", method = RequestMethod.GET)
    public @ResponseBody
    ResultTransport getSettings(String employToken) {

        Driver driver = null;
        if (StringUtils.isNotBlank(employToken)) {
            DriverLogin driverLogin = driverLoginService.selectByToken(employToken);

            if (null == driverLogin) {
                return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_ERROR);
            }

            if (System.currentTimeMillis() >= driverLogin.getDeathDate().getTime()) {
                return ResultTransport.getErrorBy(ErrorConstantV4.TOKEN_TIME_ERROR);
            }

            driver = driverService.findOne(driverLogin.getDriverId());

            if (null == driver) {
                return ResultTransport.getErrorBy(ErrorConstantV4.EMPLOY_NOT_EXISTS);
            }
        }

        try {

            Map<String, Object> map = new HashMap<String, Object>();

            Setting setting = settingUtils.get();

            map.put("allowRushOrder", setting.isAllowRushOrder());
            map.put("allowWorkCar", setting.isAllowWorkCar());
            map.put("allowWorkCarZhuandan", setting.isAllowWorkCarZhuandan());
            map.put("allowDriverZhuandan", setting.isAllowDriverZhuandan());
            map.put("allowDriverCancel", setting.isAllowDriverCancel());
            map.put("mustToPlace", setting.isMustToPlace());
            map.put("mustMemberInfo", setting.isMustMemberInfo());
            map.put("allowModifyCash", setting.isAllowModifyCash());
            map.put("allowBaoxiao", setting.isAllowBaoxiao());
            map.put("employApplyImgNessesary", setting.isEmployApplyImgNessesary());
            map.put("openHelpPay", setting.isOpenHelpPay());
            map.put("justPrice", setting.isJustPrice());
            map.put("errandFixPrice", setting.isPaotuiFixPrice());
            map.put("insurancesShow", setting.isInsurancesShow());
            map.put("lowestWorkVirtual", setting.getLowestWorkVirtual());
            map.put("payCash1", setting.getPayCash1());
            map.put("payCash2", setting.getPayCash2());
            map.put("payCash3", setting.getPayCash3());
            map.put("bookTimeZhuanxian", setting.getBookTimeZhuanxian());
            map.put("moneyBase", setting.getMoenyBase());
            map.put("startQuota", setting.getStartQuota());
            map.put("endQuota", setting.getEndQuota());

            if (null != driver) {
                map.put("driverJobType", driver.getDriverJobType());
                map.put("workCar", driver.isWorkCar());
                //分享设置
                Company company = companyService.findOne(driver.getCompanyId());
                map.put("shareTitle", company.getIntroduceTitle2());
                map.put("shareContent", company.getIntroduceContent2());
                DriverRebate driverRebate = driverRebateService.findByDriverId(company.getId());
                if (null != driverRebate) {
                    map.put("showContent", driverRebate.getContent());
                } else {
                    map.put("showContent", "");
                }
            }

            try {
                Properties prop = PropertiesLoaderUtils.loadAllProperties("config.properties");
                String daijia = prop.getProperty("function.daijia.open");
                String zhuanche = prop.getProperty("function.zhuanche.open");
                String gasstation = prop.getProperty("function.gasstation.open");
                String zuche = prop.getProperty("function.zuche.open");
                String paotui = prop.getProperty("function.paotui.open");
                String freight = prop.getProperty("function.freight.open");
                String partner = prop.getProperty("function.partner.open");
                String zhuanxian = prop.getProperty("function.zhuanxian.open");
                map.put("daijia", Boolean.valueOf(daijia));
                map.put("zhuanche", Boolean.valueOf(zhuanche));
                map.put("zuche", Boolean.valueOf(zuche));
                map.put("paotui", Boolean.valueOf(paotui));
                map.put("freight", Boolean.valueOf(freight));
                map.put("partner", Boolean.valueOf(partner));
                map.put("zhuanxian", Boolean.valueOf(zhuanxian));
                map.put("gasstation", Boolean.valueOf(gasstation));
            } catch (Exception e) {
                e.printStackTrace();
            }

            boolean aliPay = true;
            boolean weixinPay = true;
            boolean unionPay = true;
            if (StringUtils.isBlank(setting.getAlipayPartnerID()) || StringUtils
                .isBlank(setting.getAlipaySellerID()) || StringUtils
                .isBlank(setting.getAlipayPartnerPrivKey())) {
                aliPay = false;
            }
            if (StringUtils.isBlank(setting.getWxAppIDEmploy()) || StringUtils
                .isBlank(setting.getWxAppSecretEmploy()) || StringUtils
                .isBlank(setting.getWxPartnerIDEmploy()) || StringUtils
                .isBlank(setting.getWxPartnerKeyEmploy())) {
                weixinPay = false;
            }
            if (StringUtils.isBlank(setting.getMerId()) || StringUtils
                .isBlank(setting.getAcpProdEnc())
                || StringUtils.isBlank(setting.getAcpProdMiddle()) || StringUtils
                .isBlank(setting.getAcpProdRoot())
                || StringUtils.isBlank(setting.getAcpsdkSignCertPath()) || StringUtils
                .isBlank(setting.getAcpsdkSignCertPwd())) {
                unionPay = false;
            }
            map.put("aliPay", aliPay);
            map.put("weixinPay", weixinPay);
            map.put("unionPay", unionPay);

            ResultTransport instance = ResultTransport.getErrorBy(ErrorConstantV4.SUCCESS);
            instance.setData(map);

            return instance;

        } catch (Exception e) {
            log.error("api v4 driver getSettings error: {}", e);
            return ResultTransport.getErrorBy(ErrorConstantV4.SERVER_ERROR);
        }
    }

    private String getBasePath(HttpServletRequest req) {

        try {
            return WebUtils.getRealPath(req.getSession().getServletContext(), "/");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        return StringUtils.EMPTY;
    }



}
